	private static int GetDeviceKey(int keyCode)
    {  		
        switch (keyCode)
        {
        case Canvas.KEY_NUM0:
            return DK_NUM0;
        case Canvas.KEY_NUM1:
            return DK_NUM1;
        case Canvas.KEY_NUM2:
            return DK_NUM2;
        case Canvas.KEY_NUM3:
            return DK_NUM3;
        case Canvas.KEY_NUM4:
            return DK_NUM4;
        case Canvas.KEY_NUM5:
            return DK_NUM5;
        case Canvas.KEY_NUM6:
            return DK_NUM6;
        case Canvas.KEY_NUM7:
            return DK_NUM7;
        case Canvas.KEY_NUM8:
            return DK_NUM8;
        case Canvas.KEY_NUM9:
            return DK_NUM9;
        case Canvas.KEY_STAR:
            return DK_STAR;
        case Canvas.KEY_POUND:
            return DK_POUND;
        case KEY_PAD_UP:
            return DK_PAD_UP;
        case KEY_PAD_DOWN:
            return DK_PAD_DOWN;
        case KEY_PAD_LEFT:
            return DK_PAD_LEFT;
        case KEY_PAD_RIGHT:
            return DK_PAD_RIGHT;
        case KEY_PAD_MIDDLE:
            return DK_PAD_MIDDLE;
#if USE_INVERTED_SOFT_KEYS
        case KEY_SOFT_LEFT:
            return DK_SOFT_RIGHT;
        case KEY_SOFT_RIGHT:
            return DK_SOFT_LEFT;
#else	// USE_INVERTED_SOFT_KEYS
        case KEY_SOFT_LEFT:
            return DK_SOFT_LEFT;
        case KEY_SOFT_RIGHT:
            return DK_SOFT_RIGHT;
#endif	// USE_INVERTED_SOFT_KEYS
        default:
            return 0;
        }
		
    }

    private static int s_keyPressed;
    private static int s_keyPressedInStore;
    private static int s_keyCurrent;
    private static int s_keyHold;
    private static int s_keyHoldFrame;
    private static int s_keyReleased;
    private static int s_keyPrev;
    private static int s_keyPrevFrame;
    private static int s_keyCheat = GK_CHEAT1;

		
	// Cheat codes
	class Cheats
	{
		final static int Invincible = 0;
		final static int AddOneLife = 1;
		final static int EndLevel = 2;
		final static int UnlockLevels_CurDifficulty = 3;
		final static int UnlockLevels_AllDifficulties = 4;
		final static int Count = 5;
	}

	private static int[][] s_cheatCodes = 
	{
		{DK_NUM9, DK_NUM7, DK_NUM1, DK_NUM3},	//invisible
		{DK_NUM4, DK_NUM4, DK_NUM6, DK_NUM6},	//add one life
		{DK_NUM0, DK_NUM0, DK_NUM0, DK_NUM2},	//end level
		{DK_NUM1, DK_NUM1, DK_NUM1, DK_NUM3},	//unlock current difficulty
		{DK_NUM3, DK_NUM3, DK_NUM3, DK_NUM1}	//unlock all levels
	};
	
	static int s_isCheatActiveFlag;

	private static int s_currentKey = 0;
	private static int s_currentCheat = -1;

    // Update key variable each frame
    public static void UpdateKey()
    {		
        if (s_keyPressed != 0)
        {
            s_keyPrev = s_keyPressed;
            s_keyPrevFrame = 0;
        }
        s_keyPrevFrame++;

        if (s_keyHold != s_keyCurrent)
        {
	    	s_keyHoldFrame = -1;
        }

        if (s_keyHold != 0)
        {
        	s_keyHoldFrame++;
    	}

        s_keyHold = s_keyCurrent;
        s_keyPressed = s_keyReleased = 0;
    }

    protected void keyPressed(int keyCode)
    {
// #if CLEAR_KEY_FOR_UNCONTROL_MAINACTOR
        // ClearKey();
// #endif    
        s_keyPressed |= GetDeviceKey(keyCode);
        s_keyHold |= s_keyPressed;
        s_keyCurrent |= s_keyPressed;
		//System.out.println("AA:" + keyCode);
    }

    protected void keyReleased(int keyCode)
    {
        s_keyReleased	|= GetDeviceKey(keyCode);
        s_keyCurrent	&= ~s_keyReleased;
		s_keyHold		&= ~s_keyReleased;
		s_keyPressed	&= ~s_keyReleased;
    }
#if USE_ONLINE
    static boolean haveKeyPressed(int keyCode)
    {
        return (s_keyPressed & keyCode) != 0 ;//[zhibin.sang@gameloft.com]
    }

    static boolean haveKeyReleased(int keyCode)
    {
        return (s_keyPressed & keyCode) != 0;
    }
#endif
    public static void StoreAnyKeyPressed()
    {
        if (s_keyPressed != 0)
        {
            s_keyPressedInStore = s_keyPressed;
        }
    }

    public static boolean IsKeyPressedInStore(int gameKey)
    {
        return (s_keyPressedInStore & gameKey) != 0;
    }
    public static void ClearKeyPressedInStore()
    {
        s_keyPressedInStore = 0;
    }
    public static boolean IsKeyHold(int gameKey)
    {
        return (s_keyHold & gameKey) != 0;
    }

    public static boolean IsKeyPressed(int gameKey)
    {	
        	//System.out.println("Key: "+(s_keyPressed & gameKey) );
		if((s_keyPressed & gameKey) != 0)
		{
		return true;
		}
		return false;
		// return (s_keyPressed & gameKey) != 0;
		
    }

    public static boolean IsKeyReleased(int gameKey)
    {
        return (s_keyReleased & gameKey) != 0;
    }

    public static boolean IsAnyKeyHold()
    {
        return (s_keyHold & 0x1FFFF) != 0;
    }

    public static boolean IsAnyKeyPressed()
    {
        return s_keyPressed != 0;
    }

    public static void ClearKey()
    {
        s_keyCurrent = s_keyReleased = s_keyPressedInStore = 0;
    }

